﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using System.Data.Common;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data;


public abstract class BaseNode:IComparable
{
    protected XmlNode _XmlNode;
    public BaseNode(XmlNode Node)
    {
        _XmlNode = Node;
    }

    public XmlNode Node
    {
        get
        {
            return _XmlNode;
        }
    }

    public virtual int id
    {
        get
        {
            return int.Parse(_XmlNode.Attributes["id"].Value);
        }
        set
        {
            _XmlNode.Attributes["id"].Value = value.ToString();
        }
    }

    public virtual string Name
    {
        get
        {
            return _XmlNode["Name"].InnerText;
        }
        set
        {
            _XmlNode["Name"].InnerText = value.ToString();
        }
    }

    public virtual void ImportNode(XmlNode tar)
    {
        if (tar == null) return;
        if (_XmlNode == null) return;

        //delete old node
        XmlDocument doc = _XmlNode.OwnerDocument;

        //insert new node
        XmlNode pNode = _XmlNode.ParentNode;
        if (pNode == null) return;

        pNode.AppendChild(tar);

        //pNode.InsertAfter(_XmlNode, tar);

        //delete old node
        pNode.RemoveChild(_XmlNode);

        //return false;
        _XmlNode = tar;

    }


    public int CompareTo(object obj)
    {
        if (obj is BaseNode)
        {
            BaseNode temp = obj as BaseNode;
            return this.id.CompareTo(temp.id);
        }
        throw new NotImplementedException("对象不匹配！");
    }



}